package com.cabinet;

/**
* Created with IntelliJ IDEA.
* User: lesya
* Date: 1/18/14
* Time: 12:05 PM
* To change this template use File | Settings | File Templates.
*/
class OutPacket {
  volatile byte[] data = new byte[21];
  void logOutData(OutPacket prev){
    for( int i=0; i<data.length; i++ ){
      String s = "OutPacket byte " + String.format("%2d", i) + " = " + SendReceiveThread.binaryVal(data[i]);
      if( prev!=null && !SendReceiveThread.binaryVal(data[i]).equals(SendReceiveThread.binaryVal(prev.data[i])) ){
        s += " << was " + SendReceiveThread.binaryVal(prev.data[i]);
      }
      System.out.println(s);
    }
  }

  void setWorkConference(int objId, int confId, boolean in, boolean out){
    if( confId<0 || confId>7 ){
      throw new IllegalArgumentException("confId="+confId);
    }
    setBit(objId, 0, (confId & 1) !=0);
    setBit(objId, 1, (confId & 2) !=0);
    setBit(objId, 2, (confId & 4) !=0);

    // working conference participant
    setBit(objId, 3, false);
    setBit(objId, 4, false);

    setBit(objId, 6, in);
    setBit(objId, 5, out);
  }

  void setBit(int objId, int bit, boolean val){
    if( val ){
      data[objId] |= (1<<bit);
    }else{
      data[objId] &= ~(1<<bit);
    }
  }
}
